﻿
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;

using Swaf;
using Swaf.BizObj;
using Swaf.BizRule;
using Swaf.Call;
using Swaf.Container;
using Swaf.Scheduler;
using Swaf.Security;

using ICSharpCode.SharpZipLib.Zip.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Core;

namespace Forums
{
    public class ForumBackupBizRules : Syrinx.BaseBizRules
    {
        public void postExtendForumsexecuteCompanyBackup(IApplication app, IRuleContext context, object returnValue, object[] inputParams)
        {

            try
            {
                INameAddressSupport deployInfo = inputParams[2] as INameAddressSupport;
                ZipOutputStream zOut = inputParams[3] as ZipOutputStream;

                IResults rc = app.ruleMgr.execute(context, "backupCompanyArticles", "Forum", deployInfo, zOut);
                rc = app.ruleMgr.execute(context, "backupCompanyArticles", "DeletedForum", deployInfo, zOut);
            }
            catch (Exception e)
            {
                throw new BaseException("error executing postExtendProductCreateDeployment.", e);
            }
        }

        public void postExtendForumsexecuteCompanyRestore(IApplication app, IRuleContext context, object returnValue, object[] inputParams)
        {
            try
            {
                //Seems there is nothing to do here as the article restore will do the job.  We only need
                //the backup rule to specify the forum tree name.

                //INameAddressSupport backup = inputParams[2] as INameAddressSupport;
                //ZipFile zip = inputParams[3] as ZipFile;
                //IResults rc = app.ruleMgr.execute(context, "restoreCompanyArticles", backup, zip);
                //if (rc.ExceptionInfo != null)
                //    throw rc.ExceptionInfo;
            }
            catch (Exception e)
            {
                throw new BaseException("error executing postExtendProductCreateDeployment.", e);
            }
        }

        public object getForumBackupRestoreTemplate(IApplication app, IRuleContext context, object resultValue, object[] inputParams)
        {
            string template = "Forums.Gui.AspNet.BaseDeploymentOptions";
            if (resultValue != null)
                return resultValue.ToString().Length == 0 ? template
                    : new StringBuilder(50).Append(resultValue.ToString()).Append(",").Append(template).ToString();
            return template;
        }

    }
}
